package sort;

/**
 * @author Europa
 * @create 2020-05-15 19:28
 */
public class Bubble extends Sort {

    /**
     * 冒泡排序倒放<br/>
     * 可视化 https://www.bilibili.com/video/BV1yW411i7v4
     *
     * @param array int数组
     */
    @Override
    public void sort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            boolean isSorted = true;
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    exchange(array, j, i);
                    isSorted = false;
                }
            }
            if (isSorted) {
                break;
            }
        }
    }
}
